package com.crl.gen.dao;

import com.crl.dao.BaseDao;
import com.crl.gen.model.GenDbField;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/7/26 21:29
 */
@Repository
public class GenDbFieldDao extends BaseDao<GenDbField, GenDbField> {

    /**
     * 查询数据库字段
     * @param tablename
     *
     * @return
     */
    @Override
    public List<GenDbField> list(String tablename) {
        String sql = "select lower(A.COLUMN_NAME) column_name,A.DATA_TYPE,a.data_length,a.data_precision,a.data_scale,a.column_id,b.comments from user_tab_columns A,user_col_comments b\n" +
                "where a.TABLE_NAME=? and a.TABLE_NAME=b.table_name and a.COLUMN_NAME=b.column_name  " +
                "order by column_id ";
        return list(sql, tablename);
    }

    public List<GenDbField> list2(String tablename) {
        String sql = "select column_name,data_type,character_maximum_length data_length,numeric_precision data_precision,numeric_scale data_scale,column_comment comments,ordinal_position column_id\n" +
                "from information_schema.columns \n" +
                "where table_name=? and table_schema='rcdp_db'   ";
        return list(sql, tablename);
    }
}
